#include <QtTest>
#include "Logic.h"
#include "LogicReply.h"
#include "mainwindow.h"
#include "Parser.h"
#include "SessionManager.h"
#include "Storage.h"
#include "Task.h"
#include "TaskManager.h"

class toggletaskTest : public QObject {
	Q_OBJECT
private slots:
	//Integration Tests
	void invalidCommandTest_data();
	void invalidCommandTest();
	void addCommandTest_data();
	void addCommandTest();

};

void toggletaskTest::invalidCommandTest_data() {
	QTest::addColumn<QString>("actualOutput");
	QTest::addColumn<QString>("expectedOutput");

	//Add Command Tests
	QTest::newRow("Invalid Add Command: 1 more letter") << "adds" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Add Command: 3 more letters") << "adding" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Add Command: fewer letters") << "a" << "Invalid: please enter a valid command. ";

	//Delete Command Tests
	QTest::newRow("Invalid Delete Command: 1 more letter") << "deletes" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Delete Command: 3 more letters") << "deleting" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Delete Command: fewer letters") << "del" << "Invalid: please enter a valid command. ";

	//Modify Command Tests
	QTest::newRow("Invalid Modify Command: 1 more letter") << "modifys" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Modify Command: 3 more letters") << "modifying" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Modify Command: fewer letters") << "mod" << "Invalid: please enter a valid command. ";

	//Undo Command Tests
	QTest::newRow("Invalid Undo Command: 1 more letter") << "undos" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Undo Command: 3 more letters") << "undoing" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Undo Command: fewer letters") << "un" << "Invalid: please enter a valid command. ";

	//Search Command Tests
	QTest::newRow("Invalid Search Command: 1 more letter") << "searchs" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Search Command: 3 more letters") << "searching" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Search Command: fewer letters") << "sc" << "Invalid: please enter a valid command. ";

	//Display Command Tests
	QTest::newRow("Invalid Display Command: 1 more letter") << "displays" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Display Command: 3 more letters") << "displaying" << "Invalid: please enter a valid command. ";
	QTest::newRow("Invalid Display Command: fewer letters") << "disp" << "Invalid: please enter a valid command. ";

	//General Tests
	QTest::newRow("please enter a valid command.: empty string") << " " << "Invalid: please enter a valid command. ";
	QTest::newRow("please enter a valid command.: characters") << "'\'" << "Invalid: please enter a valid command. ";
	QTest::newRow("please enter a valid command.: gibberish") << "asdf" << "Invalid: please enter a valid command. ";
}

void toggletaskTest::invalidCommandTest() {
	MainWindow mainWindowTest;
	QFETCH(QString, actualOutput);
	QFETCH(QString, expectedOutput);

	QCOMPARE(mainWindowTest.testDriver(actualOutput), expectedOutput);
}

void toggletaskTest::addCommandTest_data() {
	QTest::addColumn<QString>("actualOutput");
	QTest::addColumn<QString>("expectedOutput");

	//Add Command Tests
    QTest::newRow("Add Floating Task") << "Add Floating Task" << "Added: Floating Task. ";
    QTest::newRow("Add Deadline Task Format 1") << "aDD Deadline Task 1 / 1204 / 2359" << "Added: Deadline Task 1 by 12 Apr 2359. ";
    QTest::newRow("Add Deadline Task Format 2") << "ADd Deadline Task 2 / 12 Apr / 2359" << "Added: Deadline Task 2 by 12 Apr 2359. ";
    QTest::newRow("Add Deadline Task Format 3") << "add Deadline Task 3 / 12 Apr / 11:59pm" << "Added: Deadline Task 3 by 12 Apr 2359. ";
    QTest::newRow("Add Deadline Task Format 4") << "AdD Deadline Task 4 / 12 Apr / 1159pm" << "Added: Deadline Task 4 by 12 Apr 2359. ";
    QTest::newRow("Add Meeting Task Format 1") << "add Meeting Task 1 / 1204 / 1200 / 2359" << "Added: Meeting Task 1 on 12 Apr from 1200 to 2359. ";
    QTest::newRow("Add Meeting Task Format 2") << "add Meeting Task 2 / 1204 / 12:00 / 23:59" << "Added: Meeting Task 2 on 12 Apr from 1200 to 2359. Note, there is a conflict during this time period. ";
    QTest::newRow("Add Meeting Task Format 3") << "add Meeting Task 3 / 1204 / 8:00am / 11:59pm" << "Added: Meeting Task 3 on 12 Apr from 0800 to 2359. Note, there is a conflict during this time period. ";
    QTest::newRow("Add Meeting Task Format 4") << "add Meeting Task 4 / 1204 / 1200 / 2359" << "Added: Meeting Task 4 on 12 Apr from 1200 to 2359. Note, there is a conflict during this time period. ";

	//Invalid Add Command Tests
    QTest::newRow("Add Wrong Format 1") << "add Wrong / 1204" << "Invalid: delimiter error, insufficient task parameters/please use delimiters to separate task parameters. ";
    QTest::newRow("Add Wrong Format 2") << "add Wrong / asdf / 2104" << "Invalid: unrecognized date format, please enter date in a valid format. ";
    QTest::newRow("Add Wrong Format 3") << "add Wrong / 1204 / asdf" << "Invalid: unrecognisable time format, please enter time in a valid format. ";
    QTest::newRow("Add Wrong Format 4") << "add Wrong / 1204 / 2104 / asdf" << "Invalid: unrecognisable time format, please enter time in a valid format. ";
    QTest::newRow("Add Wrong Format 5") << "add Wrong / asdf / 2104 / asdf" << "Invalid: unrecognized date format, please enter date in a valid format. ";
}

void toggletaskTest::addCommandTest() {
    MainWindow mainWindowTest;
    QFETCH(QString, actualOutput);
    QFETCH(QString, expectedOutput);

    QCOMPARE(mainWindowTest.testDriver(actualOutput), expectedOutput);
}

QTEST_MAIN(toggletaskTest);
#include "toggletaskTest.moc"